//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    // 评论快捷
    select: [
      { text: '质量好', sele: '0', },
      { text: '物流速度快', sele: '0',},
      { text: '服务态度好', sele: '0', }, 
      { text: '服务态度好', sele: '0',}, 
      { text: '尺寸无偏差', sele: '0',},
    ],
    // 店铺评分
    scoring: [
      {text: '描述相符', sele: 0, stars: [
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
      ],},
      {text: '物流服务', sele:0, stars: [
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
        ], },
      {text: '服务态度', sele:0, stars: [
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
          '../../images/favorite.png',
        ],},
    ],
    //添加照片
    add_img: [],
  },
  // 评论快捷
  text_select:function(e){
    var that=this;
    var index=e.currentTarget.dataset.index;
    var select = that.data.select;
    if (select[index].sele==0){
      select[index].sele = 1
    }else{
      select[index].sele = 0
    }
    that.setData({
      select: select,
    })
  },
  // 店铺评分
  stars_select: function (e) {
    var that = this;
    var num = e.currentTarget.dataset.num;
    var index = e.currentTarget.dataset.index;
    var scoring = that.data.scoring;

    var stars = [];
    for (var i = 0; i < scoring[num].stars.length; i++) {
      if (i <= index) {
        stars.push("../../images/favorite1.png");
      } else {
        stars.push("../../images/favorite.png");
      }
    }
    scoring[num].stars = stars;
    scoring[num].sele = ++index;
    that.setData({
      scoring: scoring,
    })
    console.log(that.data.scoring);
  },

  //添加图片
  add_img: function () {
    var _this = this;
    if (_this.data.add_img.length < 9) {
      wx.chooseImage({
        count: 9, // 选择照片的数量（默认9张） 
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有 
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有 
        success: function (res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片 

          var tempFilePaths = res.tempFilePaths
          console.log(tempFilePaths);
          // wx.uploadFile({
          //   url: '',
          //   filePath: tempFilePaths[0],
          //   name: 'file',
          //   formData: {
          //     'user': 'test'
          //   },
          //   success: function (res) {
              var add = _this.data.add_img;
              add.push(tempFilePaths);
              _this.setData({
                add_img: add,
              })
              console.log(_this.data.add_img);
          //   }
          // })
        }
      })
    }
  },




  //删除添加的图片
  delete_add_img: function (e) {
    var that = this;
    //获得点击的下标
    var index = e.currentTarget.dataset.index;
    //获取图片数组
    var add_img = that.data.add_img;
    //获取用户点击删除的图片
    var image = add_img[index];


    //请求数据（删除图片）
    // wx.request({
    //   url: 'https://hd.huwaishequ.com/Api/activity/ActivityImg_Delete',//请求地址（城市列表）
    //   data: { image: image },
    //   method: 'POST',
    //   headers: {
    //     'Content-Type': 'application/json'
    //   },
    //   success: function (res) {
        // console.log(res);
        add_img.splice(index, 1);
        that.setData({
          add_img: add_img,
        })
    //   },
    //   //接口调用失败返回的函数
    //   fail: function (err) {
    //     console.log(err)
    //   }
    // })
  },
  //提交按钮
  submit:function(){
    var that=this;
    console.log(that.data);
  },
});
